package com.junzhiit.nengji.app.rabbitmq;

import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import com.junzhiit.nengji.model.Shop;

import cn.hutool.json.JSONUtil;

@Component
@DependsOn("rabbitmqEnum") // 依赖依 RabbitmqEnum 类， 加此注解标明 rabbitmqEnum 类先加载后再加载本类
public class RabbitMQServiceImpl extends BaseRabbitMQService implements RabbitMQService{
	
	@Override
	public void sendToStoreBusiness(String id, String content) {
		try {
			toQueue(RabbitmqEnum.Queues.SHOP_BUSINESS_RECORD.getName(), id, content);
		} catch (Exception e) {
			this.sendFailure(RabbitmqEnum.Queues.SHOP_BUSINESS_RECORD.getName(), id, content);
			logger.error("发送消息至队列服务器异常............（插入失败表, 定时扫描重发）"+ RabbitmqEnum.Queues.SHOP_BUSINESS_RECORD.getName());
			e.printStackTrace();
		}
	}
	
	@Override
	public void shopUpdate(Shop shop) {
		String id = shop.getId().toString();
		String content = JSONUtil.toJsonStr(shop);
		
		try {
			toQueue(RabbitmqEnum.Queues.SHOP_UPDATE.getName(), id, content);
		} catch (Exception e) {
			this.sendFailure(RabbitmqEnum.Queues.SHOP_UPDATE.getName(), id, content);
			logger.error("发送消息至队列服务器异常............（插入失败表, 定时扫描重发）"+ RabbitmqEnum.Queues.SHOP_UPDATE.getName());
			e.printStackTrace();
		}
	}
}
